import delimited "EVS2.csv"

egen country2 = group(country)
egen gender=group(v225)
egen married=group(v234)
egen education=group(v243_edulvlb_1)
egen job=group(v244)
*v261 is income, v102 is LR, v54 is religion
*ssc install gr0070
set scheme plotplain

gen cohort2 = 0
replace cohort2 = 1 if cohort > 3

*Figure 2b
reg gen i.cohort i.gender i.married i.job v261 i.education v102 v54 i.country2 [aweight = pweight], cluster(country2)

margins, over(cohort)
marginsplot, plotopts(lcolor(white)) ytitle("Mean Gender Attitude") xtitle("Birth Cohort") title("")  xlabel(1 "< 1950" 2 "1950-9" 3 "1960-9" 4 "1970-9" 5 "1980+") ylabel(-.4(.1).6) yline(0, lpattern(shortdash))

*Figure 3b
reg im i.cohort i.country2 i.gender i.married i.job v261 i.education v102 v54 [aweight = pweight], cluster(country2)

margins, over(cohort)
marginsplot, plotopts(lcolor(white)) ytitle("Mean Immigration Attitude") xtitle("Birth Cohort") title("")  xlabel(1 "< 1950" 2 "1950-9" 3 "1960-9" 4 "1970-9" 5 "1980+") ylabel(-.4(.1).6) yline(0, lpattern(shortdash))

*appendix
reg gen i.cohort##i.country2 i.gender i.married i.job v261 i.education v102 v54, cluster(country2)

margins, at(country2 = (1(1)6)) over(cohort)
marginsplot, by(country2, label("Austria" "Denmark" "Finland" "France" "Germany" "Great Britain")) plotopts(lcolor(white)) ytitle("Mean Gender Attitude") xtitle("Birth Cohort") title("")  xlabel(1 "< 1950" 2 "1950-9" 3 "1960-9" 4 "1970-9" 5 "1980+") ylabel(-.4(.1).6) yline(0, lpattern(shortdash))

margins, at(country2 = (7(1)11)) over(cohort)
marginsplot, by(country2, label("Italy" "Netherlands" "Norway" "Sweden" "Switzerland")) plotopts(lcolor(white)) ytitle("Mean Gender Attitude") xtitle("Birth Cohort") title("")  xlabel(1 "< 1950" 2 "1950-9" 3 "1960-9" 4 "1970-9" 5 "1980+") ylabel(-.4(.1).6) yline(0, lpattern(shortdash))

reg im i.cohort##i.country2 i.gender i.married i.job v261 i.education v102 v54, cluster(country2)

margins, at(country2 = (1(1)6)) over(cohort)
marginsplot, by(country2, label("Austria" "Denmark" "Finland" "France" "Germany" "Great Britain")) plotopts(lcolor(white)) ytitle("Mean Immigration Attitude") xtitle("Birth Cohort") title("")  xlabel(1 "< 1950" 2 "1950-9" 3 "1960-9" 4 "1970-9" 5 "1980+") ylabel(-.4(.1).6) yline(0, lpattern(shortdash))

margins, at(country2 = (7(1)11)) over(cohort)
marginsplot, by(country2, label("Italy" "Netherlands" "Norway" "Sweden" "Switzerland")) plotopts(lcolor(white)) ytitle("Mean Immigration Attitude") xtitle("Birth Cohort") title("")  xlabel(1 "< 1950" 2 "1950-9" 3 "1960-9" 4 "1970-9" 5 "1980+") ylabel(-.4(.1).6) yline(0, lpattern(shortdash))

reg gen c.im##i.cohort2##i.country2 i.gender i.married i.job v261 i.education v102 v54 [aweight = pweight], cluster(country2)

margins, at(im = (-2.7(.1)2.3) country2 = (1(1)6)) over(cohort2) 
marginsplot,by(country2, label("Austria" "Denmark" "Finland" "France" "Germany" "Great Britain") recast(line) ci1opts(color(gray%20)) ci2opts(color(gray%70)) recastci(rarea) plot1opts(lpattern(".")) plot2opts(lpattern("solid")) title("") xtitle("Immigration Attitude") ytitle("Predicted Gender Attitude") legend(order(1 "Prior to 1970" 2 "1970 onward")) xlabel(-3.5(.5)3) ylabel(-.75(.25).5) yline(0, lpattern(shortdash))

margins, at(im = (-2.7(.1)2.3) country2 = (7(1)11)) over(cohort2) 
marginsplot,by(country2, label("Italy" "Netherlands" "Norway" "Sweden" "Switzerland")) recast(line) ci1opts(color(gray%20)) ci2opts(color(gray%70)) recastci(rarea) plot1opts(lpattern(".")) plot2opts(lpattern("solid")) title("") xtitle("Immigration Attitude") ytitle("Predicted Gender Attitude") legend(order(1 "Prior to 1970" 2 "1970 onward")) xlabel(-3.5(.5)3) ylabel(-.75(.25).5) yline(0, lpattern(shortdash))

margins, at(im = (-2.7(.1)2.3) country2 = (4)) over(cohort2) 
marginsplot, recast(line) ci1opts(color(gray%20)) ci2opts(color(gray%70)) recastci(rarea) plot1opts(lpattern(".")) plot2opts(lpattern("solid")) title("") xtitle("Immigration Attitude") ytitle("Predicted Gender Attitude") legend(order(1 "Prior to 1970" 2 "1970 onward")) xlabel(-3.5(.5)3) ylabel(-1.5(.25).5) yline(0, lpattern(shortdash))

margins, at(im = (-2.7(.1)2.3) country2 = (9)) over(cohort2) 
marginsplot,recast(line) ci1opts(color(gray%20)) ci2opts(color(gray%70)) recastci(rarea) plot1opts(lpattern(".")) plot2opts(lpattern("solid")) title("") xtitle("Immigration Attitude") ytitle("Predicted Gender Attitude") legend(order(1 "Prior to 1970" 2 "1970 onward")) xlabel(-3.5(.5)3) ylabel(-1.5(.25).5) yline(0, lpattern(shortdash))

margins, at(im = (-2.7(.1)2.3) country2 = (10)) over(cohort2) 
marginsplot, recast(line) ci1opts(color(gray%20)) ci2opts(color(gray%70)) recastci(rarea) plot1opts(lpattern(".")) plot2opts(lpattern("solid")) title("") xtitle("Immigration Attitude") ytitle("Predicted Gender Attitude") legend(order(1 "Prior to 1970" 2 "1970 onward")) xlabel(-3.5(.5)3) ylabel(-1.5(.25).5) yline(0, lpattern(shortdash))